package com.actionpals.components.controls
{
	import com.actionpals.enum.Align;
	
	public class CheckBox extends LabelButton
	{
		public function CheckBox()
		{			
			super();
			_paddingLeft = 0;
			_paddingRight = 0;
		}
		
		public override function get toggle():Boolean
		{	
			return true;
		}
		public override function set toggle( value:Boolean ):void
		{
			return;
		}
		
		public override function get autoRepeat():Boolean
		{ 
			return false;
		}
		public override function set autoRepeat( value:Boolean ):void
		{
			return;
		}
		
		protected override function init():void
		{
			super.init();
			super.toggle = true;
		}
		
		protected override function drawLayout():void
		{
			super.drawLayout();
			
			if( _icon )
			{
				switch( labelPlacement )
				{
					case Align.RIGHT:
						_icon.x = paddingLeft;
						labelField.x = _icon.x + ( _icon.width + iconPadding );
						_background.width = labelField.x + labelField.width + iconPadding;
						_background.height = Math.max( labelField.height, _icon.height ) + ( paddingTop + paddingBottom );
						break;
					case Align.LEFT:
						_icon.x = width - _icon.width - paddingRight;
						labelField.x = width - _icon.width - paddingRight - iconPadding - labelField.width;
						_background.width = labelField.width + _icon.width + paddingLeft + paddingRight + iconPadding;
						_background.height = Math.max( labelField.height, _icon.height ) + ( paddingTop + paddingBottom );
						break;
					case Align.TOP:
					case Align.BOTTOM:
						_background.width = Math.max( labelField.width, _icon.width ) + paddingLeft + paddingRight;
						_background.height = labelField.height + _icon.height + paddingTop + paddingBottom + iconPadding;
						break;
				}
				_background.x = Math.min( _icon.x - paddingLeft, labelField.x - paddingLeft );
				_background.y = Math.min( _icon.y - paddingTop, labelField.y - paddingTop );
			}
		}
		
		public override function drawFocus( focused:Boolean ):void
		{
			super.drawFocus( focused );
			
			if( focused )
			{
				uiFocusRect.x = _background.x - focusPadding;
				uiFocusRect.y = _background.y - focusPadding;
				
				uiFocusRect.width = _background.width + ( focusPadding<<1 );
				uiFocusRect.height = _background.height + ( focusPadding<<1 );
			}
		}
		
	}
}